<template>
  <div class="container">
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div
        :style="{height:Height +'px','overflow-y':'scroll','box-sizing': 'border-box','padding-bottom':'0.2rem'}"
      >
        <div
          class="newlist"
          v-for="(item,index) in newList"
          :key="'item'+index"
          @click="goDetail(item,item.linkUrl)"
        >
          <div class="title">{{item.title}}</div>
          <div class="type">
            <span class="zhiding" v-if="item.isTop == 1">置顶</span>
            <span class="zuixin" v-if="item.newsType == 1">最新</span>
          </div>
          <div class="time">{{item.createDate}}</div>
        </div>
      </div>
    </van-pull-refresh>
  </div>
</template>
<script>
import { Toast } from "vant";
import Api from "./../api/api";
export default {
  data() {
    return {
      isLoading: false,
      Height: "",
      newList: []
    };
  },
  methods: {
    onRefresh() {
      setTimeout(() => {
        this.getNews();
      }, 1000);
    },

    getNews() {
      this.$axios
        .get(`${Api.HTTP.getNews}?pageSize=0&pageNo=0`)
        .then(res => {
          console.log(res.data);
          this.newList = [];
          this.newList = res.data;
          this.isLoading = false;
          Toast("加载成功");
        })
        .catch(function(error) {
          Toast("网络错误");
        });
    },
    goDetail(item, linkUrl) {
      if (linkUrl == "") {
        this.$router.push({
          path: "/NewDetail",
          query: {
            item: item
          }
        });
      } else {
              this.$router.push({
          path: "/webLink",
          query: {
            url: linkUrl
          }
        });
      }
    }
  },
  mounted() {
    this.pubilcM.setTitle("新闻咨询");
    this.Height = document.documentElement.clientHeight;
    this.getNews();
  }
};
</script>
<style scoped>
.container {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  background: #f5f5f5;
}
.newlist {
  width: 100%;
  padding: 0.25rem;
  box-sizing: border-box;
  margin-bottom: 0.2rem;
  background: #fff;
}
.header {
  padding: 0.2rem;
}
.zhiding {
  background: #f73035;
  color: #fff;
  font-size: 0.2rem;
  padding: 0.02rem;
  padding-left: 0.04rem;
  padding-right: 0.04rem;
  border-radius: 0.02rem;
  text-align: center;
}
.zuixin {
  background: #dbb47f;
  color: #fff;
  font-size: 0.2rem;
  padding: 0.02rem;
  text-align: center;
  padding-left: 0.04rem;
  padding-right: 0.04rem;
  border-radius: 0.02rem;
}
.time {
  font-size: 0.24rem;
  color: #999999;
}
.title {
  font-size: 0.4rem;
  margin-bottom: 0.1rem;
}
.type {
  margin-bottom: 0.1rem;
}
</style>